﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using JMY_Models;
using JMY_IDAL;
using System.Data.SqlClient;
using System.Data;

namespace JMY_DAL
{
    public class DocLoginDAL : JMY_IDAL.DocLoginIDAL
    {
        SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=HospitalMessage;Integrated Security=True");
        public int DocLogins(string LogName, string LogPwd)
        {
            int i;
            try
            {
                conn.Open();
                string sql = "select * from T_Doc_Logins where T_DOC_UserName='" + LogName + "' and T_DOC_UserPwd='" + LogPwd + "'";
                SqlCommand cmd = new SqlCommand(sql, conn);
                i = Convert.ToInt32(cmd.ExecuteScalar());
            }
            catch (Exception ex)
            {

                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return i;
        }
        /// <summary>
        /// 自建dbherper一个
        /// </summary>
        Dbherper d = new Dbherper();
        public List<T_Doc_Logins_Model> DocGuanLiYuanShow()
        {

            DataTable dt = d.GetTable("select * from T_Doc_Logins");
            List<T_Doc_Logins_Model> list = new List<T_Doc_Logins_Model>();
            foreach(DataRow  s in dt.Rows)
            {
                T_Doc_Logins_Model login = new T_Doc_Logins_Model();
                login.T_DOC_ID =Convert.ToInt32(s["T_DOC_ID"]);
                login.T_DOC_UserName = s["T_DOC_UserName"].ToString();
                login.T_DOC_UserPwd = s["T_DOC_UserPwd"].ToString();
                list.Add(login);
            }
            return list;
        }
        /// <summary>
        /// 添加管理员信息
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public int DocGuanLiYuanAdd(string name ,string pwd)
        {
            return d.NonCaryQuery("insert into T_Doc_Logins values('" + name + "','" + pwd + "')");
        }

        /// <summary>
        /// 删除管理员信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>

        public int DocGuanLiYuanDel(int id)
        {
            return d.NonCaryQuery("delete from T_Doc_Logins where T_DOC_ID='" + id + "'");
        }
        /// <summary>
        /// 反填管理员数据
        /// </summary>
        /// <returns></returns>
        public List<T_Doc_Logins_Model> DocGuanLiYuanUpt(int id)
        {

            DataTable dt = d.GetTable("select * from T_Doc_Logins where T_DOC_ID='" + id + "'  ");
            List<T_Doc_Logins_Model> list = new List<T_Doc_Logins_Model>();
            foreach (DataRow s in dt.Rows)
            {
                T_Doc_Logins_Model login = new T_Doc_Logins_Model();
                login.T_DOC_ID = Convert.ToInt32(s["T_DOC_ID"]);
                login.T_DOC_UserName = s["T_DOC_UserName"].ToString();
                login.T_DOC_UserPwd = s["T_DOC_UserPwd"].ToString();
                list.Add(login);
            }
            return list;
        }

        public  int DocGuanLiYuanUpt2(T_Doc_Logins_Model m)
        {
            return d.NonCaryQuery("update  T_Doc_Logins set T_DOC_UserName='" + m.T_DOC_UserName + "',T_DOC_UserPwd='" + m.T_DOC_UserPwd + "' where T_DOC_ID='" + m.T_DOC_ID + "'");
        }


    }
}
